<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>转售令牌</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
    <style>
        body {
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            justify-content: flex-start;
            align-items: center;
            padding: 20px;
            background: linear-gradient(135deg, #003366 0%, #0099cc 30%, #66ccff 70%, #99ffff 100%);
        }

        .card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 24px;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 800px;
            padding: 40px;
        }

        .token-info {
            background: rgba(248, 250, 252, 0.8);
            border-radius: 16px;
            padding: 30px;
            margin-bottom: 30px;
        }

        .form-group {
            margin-bottom: 24px;
        }

        .input-field {
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            padding: 12px;
            width: 100%;
            transition: all 0.3s ease;
        }

        .input-field:focus {
            border-color: #3b82f6;
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
        }

        .btn-primary {
            background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
            color: white;
            padding: 12px 24px;
            border-radius: 8px;
            font-weight: 500;
            transition: all 0.3s ease;
            width: 100%;
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
        }

        .info-item {
            display: flex;
            justify-content: space-between;
            padding: 12px 0;
            border-bottom: 1px solid #e5e7eb;
        }

        .info-item:last-child {
            border-bottom: none;
        }

        .info-label {
            color: #64748b;
            font-weight: 500;
        }

        .info-value {
            color: #1e293b;
            font-weight: 600;
        }

        .btn-copy {
            background: #f0f9ff;
            border: none;
            border-radius: 50%;
            width: 28px;
            height: 28px;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: background 0.2s;
            margin-left: 2px;
        }

        .btn-copy:hover {
            background: #e0e7ef;
        }
    </style>
</head>

<body>
    <div class="card">
        <h1 class="text-3xl font-bold text-center mb-8 text-gray-800">转售令牌</h1>

        <div class="token-info">
            <h3 class="text-xl font-semibold mb-6 text-gray-700">令牌信息</h3>
            <div class="space-y-4">
                <div class="info-item">
                    <span class="info-label">原始令牌</span>
                    <span class="info-value">{{ token.original_token|slice:':20' }}...</span>
                </div>
                <div class="info-item">
                    <span class="info-label">当前令牌</span>
                    <span class="info-value" style="display:flex;align-items:center;gap:8px;">
                        {{ token.new_token|slice:':20' }}...
                        <button type="button" class="btn-copy" onclick="copyToken('{{ token.new_token }}')"
                            title="复制令牌">
                            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#007bff"
                                stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
                                <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
                            </svg>
                        </button>
                    </span>
                </div>
                <div class="info-item">
                    <span class="info-label">当前权限</span>
                    <span class="info-value">{{ token.permission_percentage }}%</span>
                </div>
                <div class="info-item">
                    <span class="info-label">转售后权限</span>
                    <span class="info-value">{{ token.permission_percentage|add:"-20" }}%</span>
                </div>
                <div class="info-item">
                    <span class="info-label">剩余可转售级数</span>
                    <span class="info-value">{{ token.resale_level }}</span>
                </div>
            </div>
        </div>

        <form method="post" class="space-y-6">
            {% csrf_token %}
            <div class="form-group">
                <label for="buyer_phone" class="block text-sm font-medium text-gray-700 mb-2">买家电话号码</label>
                <input type="text" id="buyer_phone" name="buyer_phone" required class="input-field">
            </div>
            <div class="form-group">
                <label for="valid_days" class="block text-sm font-medium text-gray-700 mb-2">规定使用天数</label>
                <input type="number" id="valid_days" name="valid_days" min="1" required class="input-field">
            </div>
            <button type="submit" class="btn-primary">
                确认转售
            </button>
        </form>

        {% if messages %}
        <div class="mt-6 space-y-4">
            {% for message in messages %}
            <div
                class="p-4 rounded-lg {% if message.tags == 'error' %}bg-red-100 text-red-700{% else %}bg-green-100 text-green-700{% endif %}">
                {{ message }}
            </div>
            {% endfor %}
        </div>
        {% endif %}
    </div>

    <script>
        function copyToken(token) {
            navigator.clipboard.writeText(token);
            alert('令牌已复制到剪贴板！');
        }
    </script>
</body>

</html>